import api from './index'

/**
 * 知识库相关接口
 */

/**
 * 添加知识条目
 * @param question 问题内容
 * @param answer 答案内容
 * @param serializeAnswer 是否对答案进行向量检索
 * @returns Promise
 */
export const addKnowledge = (question: string, answer: string, serializeAnswer: boolean = false) => {
  return api.post('/knowledge/add', {
    question,
    answer,
    serializeAnswer
  })
}

/**
 * 获取知识库列表
 * @param page 页码，默认为1
 * @param pageSize 每页条数，默认为100
 * @param search 搜索关键词
 * @returns Promise
 */
export const getKnowledgeList = (page: number = 1, pageSize: number = 100, search: string = '') => {
  return api.get('/knowledge/list', {
    params: {
      page,
      pageSize,
      search
    }
  })
}

/**
 * 删除知识条目
 * @param id 知识条目ID
 * @returns Promise
 */
export const deleteKnowledge = (id: number) => {
  return api.delete('/knowledge/delete', {
    params: {
      id
    }
  })
}

/**
 * 知识条目类型定义
 */
export interface KnowledgeItem {
  ID: number
  CreatedAt: string
  UpdatedAt: string
  DeletedAt: string | null
  question: string
  answer: string
  user_id: number
  q_vector_id: number
  a_vector_id: number
  category: string
  tags: string
  source: string
  access_count: number
  last_access_at: string | null
}

/**
 * 知识列表返回数据类型
 */
export interface KnowledgeListResponse {
  items: KnowledgeItem[]
  total: number
  page: number
  pageSize: number
  totalPage: number
} 